<!--
# Originally from config for buildbot.
# See third_party/buildbot_8_4p1/COPYING
-->

{% extends "layout.html" %}
{% import 'forms.html' as forms %}
{% from "change_macros.html" import change with context %}

{% block content %}

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="/p/chromiumos/gantt_chart.js"></script>
<script type="text/javascript">
  var rawSteps = [
    {% for s in b.getSteps() %}
      {'name': '{{ s.getName()|escapejs }}',
       'start': new Date({{ s.getTimes()[0] }}*1000),
       'end': new Date ({{ s.getTimes()[1] }}*1000)},
    {% endfor %}
  ];
</script>
<h1>
Builder <a href="{{ path_to_builder }}">{{ b.getBuilder().getName() }}</a>
Build #{{ b.getNumber() }}
</h1>

<div class="column">

{% if not b.isFinished() %}
  <h2>Build In Progress:</h2>

  {% if when_time %}
    <p>ETA: {{ when_time }} [{{ when }}]</p>
  {% endif %}

  {{ current_step }}
  
  {% if authz.advertiseAction('stopBuild') %}
    <h2>Stop Build</h2>
    {{ forms.stop_build(build_url+"/stop", authz, on_all=False, short=False, label='This Build') }}
  {% endif %}
{% else %}
  <h2>Results:</h2>

  <p class="{{ result_css }} result">   
    {{ b.getText()|join(' ')|capitalize }}
  </p>
   
  {% if b.getTestResults() %}
    <h3><a href="{{ tests_link }}"/></h3>
  {% endif %}
{% endif %}

<h2>SourceStamp:</h2>

<table class="info" width="100%">
{% set ss_class = cycler('alt','') %}

{% if ss.project %}
  <tr class="{{ ss_class.next() }}"><td class="left">Project</td><td>{{ ss.project|projectlink }}</td></tr>
{% endif %}

{% if ss.repository %}
  <tr class="{{ ss_class.next() }}"><td class="left">Repository</td><td>{{ ss.repository|repolink }}</td></tr>
{% endif %}

{% if ss.branch %}
  <tr class="{{ ss_class.next() }}"><td class="left">Branch</td><td>{{ ss.branch|e }}</td></tr>
{% endif %}

{% if ss.revision %}
  <tr class="{{ ss_class.next() }}"><td class="left">Revision</td><td>{{ ss.revision|revlink(ss.repository) }}</td></tr>
{% endif %}

{% if got_revision %}
  <tr class="{{ ss_class.next() }}"><td class="left">Got Revision</td><td>{{ got_revision|revlink(ss.repository) }}</td></tr>
{% endif %}

{% if ss.patch %}
  <tr class="{{ ss_class.next() }}"><td class="left">Patch</td><td>YES</td></tr>
{% endif %}

{% if ss.changes %}
  <tr class="{{ ss_class.next() }}"><td class="left">Changes</td><td>see below</td></tr>
{% endif %}

{% if most_recent_rev_build %}
  <tr class="{{ ss_class.next() }}"><td class="left" colspan="2">Build of most recent revision</td></tr>
{% endif %}

</table>

{#
 # TODO: turn this into a table, or some other sort of definition-list
 # that doesn't take up quite so much vertical space
 #}
   
<h2>BuildSlave:</h2>
  
{% if slave_url %}  
  <a href="{{ slave_url|e }}">{{ b.getSlavename()|e }}</a>
{% else %}
  {{ b.getSlavename()|e }} 
{% endif %}

<h2>Reason:</h2>
<p>
{{ b.getReason()|e }}
</p>

<h2>Steps and Logfiles:</h2>

{#
 # TODO:
 #       urls = self.original.getURLs()
 #       ex_url_class = "BuildStep external"
 #       for name, target in urls.items():
 #           text.append('[<a href="%s" class="%s">%s</a>]' %
 #                       (target, ex_url_class, html.escape(name)))
 #}

{% set nest_level = -1 %}
{% set previous_name = "unknown step" %}
{% for s in steps %}

  {# Adjust the indentation to the current step level.  We maintain as an
   # invariant that we are always in a content section (e.g. an li). #}
  {% set step_nest = s.get('nest_level', 0) %}
  {% if step_nest > nest_level %}
    {% for _ in range(nest_level, step_nest - 1) %}
    <details>
      <summary> Nested step(s) for: {{ previous_name }}</summary>
      <ol type="a"><li>
    {% endfor %}
    {% if nest_level == -1 %}
    <ol><li>
    {% else %}
    <details><summary> Nested step(s) for: {{ previous_name }}</summary><ol><li>
    {% endif %}
  {% elif step_nest == nest_level %}
    </li><li>
  {% elif step_nest < nest_level %}
    {% for _ in range(step_nest, nest_level) %}
    </li></ol></details>
    {% endfor %}
    <li>
  {% endif %}
  {% set nest_level = step_nest %}

    <div class="{{ s.css_class }} result">
      <a href="{{ s.link }}">{{ s.name }}</a> 
      {% set previous_name = s.name %}
      {{ s.text }}&nbsp;<span style="float:right">{{ '( ' + s.time_to_run + ' )' if s.time_to_run else '' }}</span>
    </div>

    <ul>
      {% set item_class = cycler('alt', '') %}
      {% for l in s.logs %}
        <li class="{{ item_class.next() }}">
          {% if l.link %}
            <a href="{{ l.link }}">{{ l.name }}</a>
          {% else %}
            <span>{{ l.name }}</span>
          {% endif %}
          {% if s.aliases %}
            {% for a in s.aliases.get(l.name, ()) %}
              <a href="{{ a.url }}">[{{ a.text }}]</a>
            {% endfor %}
          {% endif %}
        </li>
      {% else %}
        <li class="{{ item_class.next() }}">- no logs -</li>
      {% endfor %}
    
      {% for u in s.urls %}
        <li class="{{ item_class.next() }}">
          <a href="{{ u.url }}">{{ u.logname }}</a>
          {% if s.aliases %}
            {% for a in s.aliases.get(u.logname, ()) %}
              <a href="{{ a.url }}">[{{ a.text }}]</a>
            {% endfor %}
          {% endif %}
        </li>
      {% endfor %}
    </ul>  
  </li>
{% endfor %}

{# Close out all open indentation sections. #}
{% for _ in range(-1, nest_level) %}
 </li></ol>
{% endfor %}
  <div>
    <button type="button" onclick="toggleChart(rawSteps);">
      SHOW/HIDE Gantt Chart
    </button>
    <div id="chart_div"></div>
  </div>
</div>
<div class="column">

<h2>Build Properties:</h2>

<table class="info" width="100%">
<tr><th>Name</th><th>Value</th><th>Source</th></tr>

{% for p in properties %}
  {% if p.name != "blamelist" %}
    <tr class="{{ loop.cycle('alt', '') }}">
      <td class="left">{{ p.name|e }}</td>
    {% if p.short_value %}
      <td>{{ p.short_value|e }} .. [property value too long]</td>
    {% else %}
      <td>{{ p.value|e }}</td>
    {% endif %}
      <td>{{ p.source|e }}</td>
    </tr>
  {% endif %}
{% endfor %}

</table>

<h2>Timing:</h2>
<table class="info" width="100%">
  <tr class="alt"><td class="left">Start</td><td>{{ start }}</td></tr>
{% if end %}
  <tr><td class="left">End</td><td>{{ end }}</td></tr>
{% endif %}
  <tr {{ 'class="alt"' if end else '' }}><td class="left">Elapsed</td><td>{{ elapsed }}</td></tr>
</table>

</div>

<br style="clear:both"/>
  
{% endblock %}
